//
//  MainWindowController.swift
//  OnemeetingDemo
//
//  Created by zhangheng on 2019/11/18.
//  Copyright © 2019 www.onemeeting.1meetingIos. All rights reserved.
//

import Foundation

class MainWindowController: NSWindowController {
    
    override init(window: NSWindow?) {
        super.init(window: window)
        
        self.window = self.keyWindow
        self.contentViewController = viewController
        self.window?.center()
    }
    
    lazy var viewController: MainViewController = {
        let viewController = MainViewController()
        return viewController
    }()
    
    
    
    lazy var keyWindow: NSWindow = {
        let frame: CGRect = CGRect(x: 0, y: 0, width: kWindowWidth, height: kWindowHeight)
        let style: NSWindow.StyleMask = []
        let back: NSWindow.BackingStoreType = .buffered
        let window: NSWindow = NSWindow(contentRect: frame, styleMask: style, backing: back, defer: false)
        window.minSize = CGSize.init(width: kWindowWidth, height: kWindowHeight)
        //window.title = "壹会通"
        window.collectionBehavior = NSWindow.CollectionBehavior.fullScreenNone
        
        //设置圆角
        window.contentView?.layer?.masksToBounds = true
        window.contentView?.layer?.cornerRadius = 5
        window.contentView?.wantsLayer = true
        window.backgroundColor = NSColor.clear
        
        //阴影
        window.hasShadow = true
        
        window.level = NSWindow.Level.normal
        
        //win拖动
        window.isMovableByWindowBackground = true
        window.titlebarAppearsTransparent = true
        window.titleVisibility = .hidden
        window.styleMask = [.fullSizeContentView,.titled,.closable,.miniaturizable]
        window.windowController = self
        window.standardWindowButton(NSWindow.ButtonType.zoomButton)?.isHidden = true
        
        window.center()
        return window
    }()
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}


class WindowEngine: NSObject {
    public class func keyWindow() -> NSWindow?{
        let appDt = NSApplication.shared.delegate as? AppDelegate
        let win = appDt?.windowController.keyWindow
        return win
    }
}


